package com.ysm.smfu.map;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.maps.AMap;
import com.amap.api.maps.AMapUtils;
import com.amap.api.maps.model.Marker;
import com.ysm.smfu.R;
import com.ysm.smfu.utils.AMapUtil;
import com.ysm.smfu.utils.UIUtils;

/**
 * 作者：zhuTH on 2017/4/20 13:23
 */
public class CustomeInfoWindow implements AMap.InfoWindowAdapter {

    private final Activity activity;

    public CustomeInfoWindow(Activity activity) {
        this.activity = activity;
    }

    @Override
    public View getInfoWindow(Marker marker) {
        return null;
    }

    /**
     * 监听自定义infowindow窗口的infowindow事件回调
     */
    @Override
    public View getInfoContents(Marker marker) {
        View view = LayoutInflater.from(UIUtils.getContext()).inflate(R.layout.markinfowindow, null);
        rendView(marker, view);
        return view;
    }

    /**
     * 处理view显示
     *
     * @param view
     */
    private void rendView(final Marker marker, View view) {
        TextView textView = (TextView) view.findViewById(R.id.text);
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
//        textView.setText(marker.getSnippet());
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FoodMapUtils.startMap(activity, marker.getPosition(), marker.getTitle());
                marker.hideInfoWindow();
            }
        });
    }
}
